<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人资料 - Demo系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }

        /* 导航栏样式 */
        .navbar {
            background: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0 20px;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .nav-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 70px;
        }

        .nav-logo {
            font-size: 24px;
            font-weight: 700;
            color: #333;
            text-decoration: none;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .nav-actions {
            display: flex;
            gap: 15px;
            align-items: center;
        }

        .nav-btn {
            padding: 8px 16px;
            background: transparent;
            border: 2px solid #667eea;
            color: #667eea;
            border-radius: 20px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .nav-btn:hover {
            background: #667eea;
            color: white;
        }

        .nav-btn.primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            color: white;
        }

        .nav-btn.primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }

        /* 主内容区域 */
        .main-container {
            max-width: 800px;
            margin: 40px auto;
            padding: 0 20px;
        }

        /* 个人资料卡片 */
        .profile-card {
            background: white;
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            position: relative;
            overflow: hidden;
        }

        .profile-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #667eea, #764ba2);
        }

        .profile-header {
            text-align: center;
            margin-bottom: 40px;
            padding-bottom: 30px;
            border-bottom: 2px solid #f0f0f0;
        }

        .profile-avatar {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 36px;
            font-weight: 600;
            margin: 0 auto 20px;
        }

        .profile-title {
            font-size: 28px;
            font-weight: 600;
            color: #333;
            margin-bottom: 8px;
        }

        .profile-subtitle {
            color: #666;
            font-size: 16px;
        }

        /* 表单样式 */
        .profile-form {
            display: none;
        }

        .profile-form.active {
            display: block;
        }

        .profile-info {
            display: block;
        }

        .profile-info.hidden {
            display: none;
        }

        .info-group, .form-group {
            margin-bottom: 25px;
        }

        .info-label, .form-label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
            font-size: 14px;
        }

        .info-value {
            padding: 12px 16px;
            background-color: #f8f9fa;
            border: 2px solid #e1e5e9;
            border-radius: 10px;
            font-size: 16px;
            color: #333;
        }

        .form-input {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e1e5e9;
            border-radius: 10px;
            font-size: 16px;
            transition: all 0.3s ease;
            background-color: #f8f9fa;
        }

        .form-input:focus {
            outline: none;
            border-color: #667eea;
            background-color: white;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        .form-input.error {
            border-color: #dc3545;
        }

        .form-input.success {
            border-color: #28a745;
        }

        .error-message {
            color: #dc3545;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }

        .success-message {
            color: #28a745;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }

        /* 密码强度指示器 */
        .password-strength {
            margin-top: 8px;
            display: none;
        }

        .strength-bar {
            width: 100%;
            height: 4px;
            background-color: #e1e5e9;
            border-radius: 2px;
            overflow: hidden;
        }

        .strength-fill {
            height: 100%;
            width: 0%;
            border-radius: 2px;
            transition: all 0.3s ease;
        }

        .strength-text {
            font-size: 12px;
            margin-top: 4px;
            color: #666;
        }

        /* 按钮样式 */
        .btn-group {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }

        .btn {
            flex: 1;
            padding: 14px 24px;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }

        .btn-secondary {
            background: #f8f9fa;
            color: #666;
            border: 2px solid #e1e5e9;
        }

        .btn-secondary:hover {
            background: #e9ecef;
            color: #333;
        }

        .btn:disabled {
            background: #ccc;
            cursor: not-allowed;
            transform: none;
        }

        /* 提示信息 */
        .alert {
            padding: 12px 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-size: 14px;
            display: none;
        }

        .alert-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .alert-error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        /* 验证提示 */
        .field-check {
            display: inline-block;
            width: 16px;
            height: 16px;
            margin-left: 8px;
            border-radius: 50%;
            font-size: 10px;
            text-align: center;
            line-height: 16px;
            color: white;
            font-weight: bold;
        }

        .field-check.checking {
            background-color: #ffc107;
        }

        .field-check.success {
            background-color: #28a745;
        }

        .field-check.error {
            background-color: #dc3545;
        }

        /* 加载动画 */
        .loading {
            display: none;
            text-align: center;
            margin-top: 10px;
        }

        .loading-spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid #f3f3f3;
            border-top: 2px solid #667eea;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .main-container {
                padding: 0 15px;
            }

            .profile-card {
                padding: 30px 20px;
            }

            .profile-title {
                font-size: 24px;
            }

            .btn-group {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="nav-container">
            <a href="index.html" class="nav-logo">Demo系统</a>
            <div class="nav-actions">
                <a href="index.html" class="nav-btn">返回首页</a>
                <button class="nav-btn" onclick="logout()">退出登录</button>
            </div>
        </div>
    </nav>

    <!-- 主内容区域 -->
    <div class="main-container">
        <div class="profile-card">
            <div class="profile-header">
                <div class="profile-avatar" id="profileAvatar"></div>
                <h1 class="profile-title" id="profileUsername"></h1>
                <p class="profile-subtitle">管理您的个人信息和账户设置</p>
            </div>

            <div id="alert" class="alert"></div>

            <!-- 个人信息显示 -->
            <div id="profileInfo" class="profile-info">
                <div class="info-group">
                    <label class="info-label">用户名</label>
                    <div class="info-value" id="displayUsername"></div>
                </div>

                <div class="info-group">
                    <label class="info-label">邮箱地址</label>
                    <div class="info-value" id="displayEmail"></div>
                </div>

                <div class="info-group">
                    <label class="info-label">手机号码</label>
                    <div class="info-value" id="displayPhone"></div>
                </div>

                <div class="info-group">
                    <label class="info-label">注册时间</label>
                    <div class="info-value" id="displayCreateTime"></div>
                </div>

                <div class="btn-group">
                    <button class="btn btn-primary" onclick="enableEdit()">编辑资料</button>
                    <button class="btn btn-secondary" onclick="window.history.back()">返回</button>
                </div>
            </div>

            <!-- 个人资料编辑表单 -->
            <form id="profileForm" class="profile-form">
                <div class="form-group">
                    <label class="form-label">用户名（不可修改）</label>
                    <input type="text" class="form-input" id="editUsername" readonly style="background-color: #e9ecef;">
                </div>

                <div class="form-group">
                    <label class="form-label">
                        邮箱地址
                        <span id="emailCheck" class="field-check" style="display: none;"></span>
                    </label>
                    <input type="email" class="form-input" id="editEmail" required>
                    <div class="error-message" id="editEmailError"></div>
                    <div class="success-message" id="editEmailSuccess"></div>
                </div>

                <div class="form-group">
                    <label class="form-label">
                        手机号码
                        <span id="phoneCheck" class="field-check" style="display: none;"></span>
                    </label>
                    <input type="tel" class="form-input" id="editPhone">
                    <div class="error-message" id="editPhoneError"></div>
                    <div class="success-message" id="editPhoneSuccess"></div>
                </div>

                <div class="form-group">
                    <label class="form-label">新密码（可选，留空则不修改）</label>
                    <input type="password" class="form-input" id="newPassword">
                    <div class="password-strength" id="passwordStrength">
                        <div class="strength-bar">
                            <div class="strength-fill" id="strengthFill"></div>
                        </div>
                        <div class="strength-text" id="strengthText">密码强度</div>
                    </div>
                    <div class="error-message" id="newPasswordError"></div>
                </div>

                <div class="form-group" id="confirmPasswordGroup" style="display: none;">
                    <label class="form-label">确认新密码</label>
                    <input type="password" class="form-input" id="confirmPassword">
                    <div class="error-message" id="confirmPasswordError"></div>
                    <div class="success-message" id="confirmPasswordSuccess"></div>
                </div>

                <div class="form-group" id="currentPasswordGroup" style="display: none;">
                    <label class="form-label">当前密码（修改密码时必填）</label>
                    <input type="password" class="form-input" id="currentPassword">
                    <div class="error-message" id="currentPasswordError"></div>
                </div>

                <div class="loading" id="loading">
                    <div class="loading-spinner"></div>
                    <span style="margin-left: 10px; color: #666;">正在更新...</span>
                </div>

                <div class="btn-group">
                    <button type="submit" class="btn btn-primary">保存修改</button>
                    <button type="button" class="btn btn-secondary" onclick="cancelEdit()">取消</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        // API基础URL
        const API_BASE_URL = 'http://localhost:8080/api';

        // 当前用户信息
        let currentUser = null;
        let isEditing = false;

        // 防抖函数
        function debounce(func, wait) {
            let timeout;
            return function executedFunction(...args) {
                const later = () => {
                    clearTimeout(timeout);
                    func(...args);
                };
                clearTimeout(timeout);
                timeout = setTimeout(later, wait);
            };
        }

        // 页面加载时初始化
        window.addEventListener('load', function() {
            initializePage();
        });

        // 初始化页面
        function initializePage() {
            // 检查用户登录状态
            const userStr = localStorage.getItem('user');
            if (!userStr) {
                window.location.href = 'login.html';
                return;
            }

            try {
                currentUser = JSON.parse(userStr);
                loadUserProfile();
                setupEventListeners();
            } catch (error) {
                console.error('解析用户信息失败:', error);
                localStorage.removeItem('user');
                window.location.href = 'login.html';
            }
        }

        // 加载用户个人资料
        async function loadUserProfile() {
            try {
                const response = await fetch(`${API_BASE_URL}/user/${currentUser.id}/profile`);
                const result = await response.json();

                if (result.code === 0) {
                    currentUser = result.data;
                    localStorage.setItem('user', JSON.stringify(currentUser));
                    displayUserInfo();
                } else {
                    showAlert('获取用户信息失败：' + result.message, 'error');
                }
            } catch (error) {
                console.error('获取用户信息失败:', error);
                showAlert('网络错误，请稍后重试', 'error');
            }
        }

        // 显示用户信息
        function displayUserInfo() {
            // 设置头像
            document.getElementById('profileAvatar').textContent = currentUser.username.charAt(0).toUpperCase();
            document.getElementById('profileUsername').textContent = currentUser.username;

            // 显示详细信息
            document.getElementById('displayUsername').textContent = currentUser.username;
            document.getElementById('displayEmail').textContent = currentUser.email || '未设置';
            document.getElementById('displayPhone').textContent = currentUser.phone || '未设置';
            document.getElementById('displayCreateTime').textContent = formatDateTime(currentUser.createTime);

            // 填充编辑表单
            document.getElementById('editUsername').value = currentUser.username;
            document.getElementById('editEmail').value = currentUser.email || '';
            document.getElementById('editPhone').value = currentUser.phone || '';
        }

        // 格式化日期时间
        function formatDateTime(dateTimeStr) {
            const date = new Date(dateTimeStr);
            return date.toLocaleString('zh-CN', {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit'
            });
        }

        // 启用编辑模式
        function enableEdit() {
            isEditing = true;
            document.getElementById('profileInfo').classList.add('hidden');
            document.getElementById('profileForm').classList.add('active');
            hideAlert();
        }

        // 取消编辑
        function cancelEdit() {
            isEditing = false;
            document.getElementById('profileInfo').classList.remove('hidden');
            document.getElementById('profileForm').classList.remove('active');
            
            // 重置表单
            document.getElementById('profileForm').reset();
            displayUserInfo();
            clearErrors();
            hideAlert();
        }

        // 设置事件监听器
        function setupEventListeners() {
            const profileForm = document.getElementById('profileForm');
            const newPasswordInput = document.getElementById('newPassword');
            const confirmPasswordInput = document.getElementById('confirmPassword');
            const editEmailInput = document.getElementById('editEmail');
            const editPhoneInput = document.getElementById('editPhone');

            // 表单提交
            profileForm.addEventListener('submit', handleFormSubmit);

            // 新密码输入监听
            newPasswordInput.addEventListener('input', function() {
                const password = this.value;
                
                if (password) {
                    document.getElementById('confirmPasswordGroup').style.display = 'block';
                    document.getElementById('currentPasswordGroup').style.display = 'block';
                    checkPasswordStrength(password);
                } else {
                    document.getElementById('confirmPasswordGroup').style.display = 'none';
                    document.getElementById('currentPasswordGroup').style.display = 'none';
                    document.getElementById('passwordStrength').style.display = 'none';
                }
            });

            // 确认密码输入监听
            confirmPasswordInput.addEventListener('input', function() {
                const newPassword = newPasswordInput.value;
                const confirmPassword = this.value;

                if (confirmPassword) {
                    if (newPassword === confirmPassword) {
                        showFieldSuccess('confirmPassword', '密码匹配');
                    } else {
                        showFieldError('confirmPassword', '两次输入的密码不一致');
                    }
                }
            });

            // 邮箱和手机号实时验证（防抖）
            const debouncedCheckEmail = debounce((value) => checkEmailAvailability(value), 500);
            const debouncedCheckPhone = debounce((value) => checkPhoneAvailability(value), 500);

            editEmailInput.addEventListener('input', function() {
                const value = this.value.trim();
                if (value && value !== currentUser.email && isValidEmail(value)) {
                    debouncedCheckEmail(value);
                } else {
                    document.getElementById('emailCheck').style.display = 'none';
                }
            });

            editPhoneInput.addEventListener('input', function() {
                const value = this.value.trim();
                if (value && value !== currentUser.phone && isValidPhone(value)) {
                    debouncedCheckPhone(value);
                } else {
                    document.getElementById('phoneCheck').style.display = 'none';
                }
            });

            // 输入框焦点事件
            document.querySelectorAll('.form-input').forEach(input => {
                input.addEventListener('focus', function() {
                    this.classList.remove('error');
                    const errorElement = document.getElementById(this.id + 'Error');
                    if (errorElement) {
                        errorElement.style.display = 'none';
                    }
                });
            });
        }

        // 处理表单提交
        async function handleFormSubmit(e) {
            e.preventDefault();

            if (!validateForm()) {
                return;
            }

            showLoading(true);

            const formData = {
                email: document.getElementById('editEmail').value.trim(),
                phone: document.getElementById('editPhone').value.trim(),
            };

            const newPassword = document.getElementById('newPassword').value.trim();
            if (newPassword) {
                formData.newPassword = newPassword;
                formData.confirmPassword = document.getElementById('confirmPassword').value.trim();
                formData.currentPassword = document.getElementById('currentPassword').value.trim();
            }

            try {
                const response = await fetch(`${API_BASE_URL}/user/${currentUser.id}/profile`, {
                    method: 'PUT',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(formData)
                });

                const result = await response.json();

                if (result.code === 0) {
                    showAlert('个人资料更新成功！', 'success');
                    currentUser = result.data;
                    localStorage.setItem('user', JSON.stringify(currentUser));
                    displayUserInfo();
                    
                    setTimeout(() => {
                        cancelEdit();
                    }, 1500);
                } else {
                    showAlert(result.message || '更新失败', 'error');
                }
            } catch (error) {
                console.error('更新请求失败:', error);
                showAlert('网络错误，请稍后重试', 'error');
            } finally {
                showLoading(false);
            }
        }

        // 表单验证
        function validateForm() {
            let isValid = true;
            clearErrors();

            const email = document.getElementById('editEmail').value.trim();
            const phone = document.getElementById('editPhone').value.trim();
            const newPassword = document.getElementById('newPassword').value.trim();
            const confirmPassword = document.getElementById('confirmPassword').value.trim();
            const currentPassword = document.getElementById('currentPassword').value.trim();

            // 邮箱验证
            if (!email) {
                showFieldError('editEmail', '邮箱不能为空');
                isValid = false;
            } else if (!isValidEmail(email)) {
                showFieldError('editEmail', '邮箱格式不正确');
                isValid = false;
            }

            // 手机号验证
            if (phone && !isValidPhone(phone)) {
                showFieldError('editPhone', '手机号格式不正确');
                isValid = false;
            }

            // 密码验证
            if (newPassword) {
                if (newPassword.length < 6 || newPassword.length > 20) {
                    showFieldError('newPassword', '密码长度必须在6-20位之间');
                    isValid = false;
                }

                if (!confirmPassword) {
                    showFieldError('confirmPassword', '请确认新密码');
                    isValid = false;
                } else if (newPassword !== confirmPassword) {
                    showFieldError('confirmPassword', '两次输入的密码不一致');
                    isValid = false;
                }

                if (!currentPassword) {
                    showFieldError('currentPassword', '修改密码时必须提供当前密码');
                    isValid = false;
                }
            }

            return isValid;
        }

        // 检查邮箱可用性
        async function checkEmailAvailability(email) {
            const checkElement = document.getElementById('emailCheck');
            
            checkElement.style.display = 'inline-block';
            checkElement.className = 'field-check checking';
            checkElement.textContent = '?';

            try {
                const response = await fetch(`${API_BASE_URL}/user/check-email-exclude?email=${encodeURIComponent(email)}&excludeUserId=${currentUser.id}`);
                const result = await response.json();

                if (result.code === 0) {
                    if (result.data) {
                        showFieldError('editEmail', '该邮箱已被其他用户使用');
                        checkElement.className = 'field-check error';
                        checkElement.textContent = '✕';
                    } else {
                        showFieldSuccess('editEmail', '该邮箱可以使用');
                        checkElement.className = 'field-check success';
                        checkElement.textContent = '✓';
                    }
                }
            } catch (error) {
                console.error('检查邮箱失败:', error);
                checkElement.style.display = 'none';
            }
        }

        // 检查手机号可用性
        async function checkPhoneAvailability(phone) {
            const checkElement = document.getElementById('phoneCheck');
            
            checkElement.style.display = 'inline-block';
            checkElement.className = 'field-check checking';
            checkElement.textContent = '?';

            try {
                const response = await fetch(`${API_BASE_URL}/user/check-phone-exclude?phone=${encodeURIComponent(phone)}&excludeUserId=${currentUser.id}`);
                const result = await response.json();

                if (result.code === 0) {
                    if (result.data) {
                        showFieldError('editPhone', '该手机号已被其他用户使用');
                        checkElement.className = 'field-check error';
                        checkElement.textContent = '✕';
                    } else {
                        showFieldSuccess('editPhone', '该手机号可以使用');
                        checkElement.className = 'field-check success';
                        checkElement.textContent = '✓';
                    }
                }
            } catch (error) {
                console.error('检查手机号失败:', error);
                checkElement.style.display = 'none';
            }
        }

        // 密码强度检测
        function checkPasswordStrength(password) {
            const strengthIndicator = document.getElementById('passwordStrength');
            const strengthFill = document.getElementById('strengthFill');
            const strengthText = document.getElementById('strengthText');

            strengthIndicator.style.display = 'block';

            let score = 0;
            let strength = '';
            let color = '';

            // 长度检查
            if (password.length >= 6) score++;
            if (password.length >= 8) score++;

            // 包含数字
            if (/\d/.test(password)) score++;

            // 包含小写字母
            if (/[a-z]/.test(password)) score++;

            // 包含大写字母
            if (/[A-Z]/.test(password)) score++;

            // 包含特殊字符
            if (/[^A-Za-z0-9]/.test(password)) score++;

            // 根据分数确定强度
            if (score <= 2) {
                strength = '弱';
                color = '#dc3545';
            } else if (score <= 4) {
                strength = '中等';
                color = '#ffc107';
            } else {
                strength = '强';
                color = '#28a745';
            }

            strengthFill.style.width = `${(score / 6) * 100}%`;
            strengthFill.style.backgroundColor = color;
            strengthText.textContent = `密码强度：${strength}`;
            strengthText.style.color = color;
        }

        // 验证邮箱格式
        function isValidEmail(email) {
            const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            return emailRegex.test(email);
        }

        // 验证手机号格式
        function isValidPhone(phone) {
            const phoneRegex = /^1[3-9]\d{9}$/;
            return phoneRegex.test(phone);
        }

        // 显示字段错误
        function showFieldError(field, message) {
            const input = document.getElementById(field);
            const error = document.getElementById(field + 'Error');
            const success = document.getElementById(field + 'Success');

            input.classList.add('error');
            input.classList.remove('success');
            error.textContent = message;
            error.style.display = 'block';
            if (success) success.style.display = 'none';
        }

        // 显示字段成功
        function showFieldSuccess(field, message) {
            const input = document.getElementById(field);
            const error = document.getElementById(field + 'Error');
            const success = document.getElementById(field + 'Success');

            input.classList.remove('error');
            input.classList.add('success');
            error.style.display = 'none';
            if (success) {
                success.textContent = message;
                success.style.display = 'block';
            }
        }

        // 清除错误状态
        function clearErrors() {
            const inputs = document.querySelectorAll('.form-input');
            const errors = document.querySelectorAll('.error-message');
            const successes = document.querySelectorAll('.success-message');

            inputs.forEach(input => {
                input.classList.remove('error', 'success');
            });
            errors.forEach(error => error.style.display = 'none');
            successes.forEach(success => success.style.display = 'none');
        }

        // 显示/隐藏加载状态
        function showLoading(show) {
            const loading = document.getElementById('loading');
            const submitBtn = document.querySelector('button[type="submit"]');
            
            if (show) {
                loading.style.display = 'block';
                submitBtn.disabled = true;
            } else {
                loading.style.display = 'none';
                submitBtn.disabled = false;
            }
        }

        // 显示提示信息
        function showAlert(message, type) {
            const alert = document.getElementById('alert');
            alert.textContent = message;
            alert.className = `alert alert-${type}`;
            alert.style.display = 'block';
        }

        // 隐藏提示信息
        function hideAlert() {
            document.getElementById('alert').style.display = 'none';
        }

        // 退出登录
        function logout() {
            if (confirm('确定要退出登录吗？')) {
                localStorage.removeItem('user');
                window.location.href = 'login.html';
            }
        }
    </script>
</body>
</html>
